<template>
  <fullscreen style="height: 100vh" :fullscreen.sync="fullscreen">
    <el-container class="home-container">
      <!-- 头部区域 -->
      <el-header>
        <div>
          <img src="@/assets/imgs/ddw.jpg" alt />
          <span class="header_title">建筑构件生产管理系统</span>
        </div>
        <!-- <el-button>登录</el-button> -->
        <div>
          <span
            @click="fullscreen = true"
            style="
              color: #fff;
              font-size: 30px;
              cursor: pointer;
              margin-right: 20px;
            "
            class="iconfont"
            :class="fullscreen ? '' : 'icon-quanping_o'"
          ></span>
          <el-dropdown @command="handleCommand">
            <div class="el-dropdown-link">
              <div class="header_right">
                <img src="@/assets/icon_user.jpg" alt />
              </div>
              admin
              <i class="el-icon-arrow-down el-icon--right"></i>
            </div>
            <el-dropdown-menu slot="dropdown">
              <!-- <el-dropdown-item command="home">系统首页</el-dropdown-item> -->
              <el-dropdown-item command="loginOut">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <!-- 页面主体区域 -->
      <el-container>
        <!-- 侧边栏 -->
        <el-aside :width="!isCollapse ? '200px' : '80px'">
          <el-checkbox-group v-model="isCollapse">
            <el-checkbox-button style="width: 100%"> ||| </el-checkbox-button>
          </el-checkbox-group>
          <el-menu
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409eff"
            :collapse="isCollapse"
            class="el-menu-vertical-demo"
            :router="true"
            :collapse-transition="false"
            :unique-opened="true"
            :default-active="$route.path"
          >
            <el-submenu :index="item.id" v-for="item in menus" :key="item.id">
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{ item.name }}</span>
              </template>
              <!-- 二级菜单 -->
              <el-menu-item
                :index="subItem.path"
                v-for="subItem in item.submenus"
                :key="subItem.path"
              >
                <template slot="title"
                  ><span>{{ subItem.name }}</span></template
                >
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 右侧内容主题 -->
        <el-main style="flex-grow: 1; padding: unset">
          <!-- Main -->
          <router-view></router-view>
        </el-main>
      </el-container>
      <el-dialog
        title="温馨提示"
        :visible.sync="centerDialogVisible"
        width="40%"
        center
      >
        <div style="text-align: center">您确定退出当前系统吗？</div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="loginOut">确 定</el-button>
        </span>
      </el-dialog>
    </el-container>
  </fullscreen>
</template>

<script>
import common from '@/utils/common'
import { findDimensions } from '@/utils/index'
export default {
  created() {
    console.log(this.menus)
    window.onresize = () => {
      if (findDimensions() < 960) this.isCollapse = true
      else this.isCollapse = false
    }
  },
  data() {
    return {
      arr: [],
      centerDialogVisible: false,
      isCollapse: false,
      menus: common.items,
      fullscreen: false,
    }
  },

  methods: {
    handleCommand(command) {
      switch (command) {
        case 'home':
          this.$router.push('/home')
          break
        case 'loginOut':
          this.centerDialogVisible = true
          break
        default:
          console.log('错误路由')
          break
      }
    },

    // 退出登录  清除token
    loginOut() {
      console.log('确定退出登录了')
      this.centerDialogVisible = false
      this.$router.push('/')
    },
  },
}
</script>

<style lang="scss" scoped>
.header_title {
  white-space: nowrap;
}
.el-checkbox-group {
  text-align: center;
  padding: 10px 0;
  cursor: pointer;
}

::v-deep .el-checkbox-button.is-checked .el-checkbox-button__inner {
  background: unset;
  border-color: unset;
  box-shadow: unset;
}
::v-deep .el-checkbox-button:first-child .el-checkbox-button__inner {
  border: unset;
}
::v-deep .el-checkbox-button__inner {
  width: 100%;
  text-align: center;
  background: unset;
  padding: unset;
  color: #fff;
  border: unset;
}
.home-container {
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  height: 100%;
}

.el-header {
  width: 100%;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  background-color: rgba(95, 112, 165, 1);
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 10px;
    }
    img {
      width: 40px;
      height: 40px;
      border-radius: 10px;
      object-fit: fill;
    }
  }
  .el-dropdown-link {
    color: #fff;
    display: flex;
    cursor: pointer;
    align-items: center;
    justify-content: space-between;
  }
  .header_right {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 20px;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
    }
  }
}

.el-header img {
  height: 30px;
  width: 30px;
}

.el-aside {
  overflow: hidden;
  background: #333744;
  .el-menu {
    border-right: none;
  }
}

.el-submenu {
  color: yellow;
}

.el-main {
  // height: calc(100vh - 80px);
  height: 100vh;
  padding-bottom: 30px;
  color: #333;
  overflow-y: auto;
}
</style>